#!/usr/bin/env python

import unittest
from storage import Storage
import util

class TestStorage(Storage, unittest.TestCase):
  def __init__(self, *args, **kwargs):
    unittest.TestCase.__init__(self, *args, **kwargs)
    Storage.__init__(self)

  def setUp(self):
    #print "setUp"
    pass

  def tearDown(self):
    #print "tearDown"
    pass

  def test_addSecondaryStorage(self):
    url = "nfs://172.16.236.32/secondary_" + util.getUniqueStr()
    zoneid = 2
    response = self.addSecondaryStorage(url, zoneid=zoneid)
    self.assertEqual(response["name"], url)
    self.assertEqual(response["zoneid"], zoneid)

  def test_destroySecondaryStorage(self):
    url = "nfs://172.16.236.32/secondary_" + util.getUniqueStr()
    zoneid = 2
    addResponse = self.addSecondaryStorage(url, zoneid=zoneid)
    secondarystorageid = addResponse["id"]
    response = self.destroySecondaryStorage(secondarystorageid)
    self.assertEqual(response["success"], "true")

  def test_listSecondaryStorages(self):
    response = self.listSecondaryStorages()
    self.assertTrue(len(response) == 0 or response['count'] > 0)

  def test_listStoragePools(self):
    response = self.listStoragePools()
    self.assertTrue(len(response) == 0 or response['count'] > 0)

  def test_createStoragePool(self):
    name = "primary26_130"  
    url = "nfs://172.16.236.132/primary-27" 
    clusterid = 1 
    podid = 1
    zoneid = 1
    response = self.createStoragePool(name, url, clusterid, zoneid, podid=podid)
    self.assertEqual(response["name"],name)
    self.assertEqual(response["zoneid"],zoneid)

  def test_enableStorageMaintenance(self):
    storageid = 204
    response = self.enableStorageMaintenance(storageid)
    self.assertEqual(response["id"], storageid)
    self.assertEqual(response["state"], "Maintenance")

  def test_cancelStorageMaintenance(self):
    storageid = 204
    response = self.cancelStorageMaintenance(storageid)
    self.assertEqual(response["id"], storageid)
    self.assertEqual(response["state"], "Up")

  def test_deleteStoragePool(self):
    name = "primary26_130_delete"
    url = "nfs://172.16.236.130/primary-26-delete"
    clusterid = 1
    podid = 1
    zoneid = 1
    addResponse = self.createStoragePool(name, url, clusterid, zoneid, podid=podid)
    storageid = addResponse["id"]
    response = self.deleteStoragePool(storageid)
    self.assertEqual(response["success"], "true")


def get_suite():
  suite = unittest.TestSuite()
  #suite.addTest(TestStorage("test_addSecondaryStorage"))
  #suite.addTest(TestStorage("test_destroySecondaryStorage"))
  #suite.addTest(TestStorage("test_listSecondaryStorages"))
  #suite.addTest(TestStorage("test_listStoragePools"))
  suite.addTest(TestStorage("test_createStoragePool"))
  #suite.addTest(TestStorage("test_enableStorageMaintenance"))
  #suite.addTest(TestStorage("test_cancelStorageMaintenance"))
  suite.addTest(TestStorage("test_deleteStoragePool"))
  return suite

if __name__ == "__main__":
  suite = get_suite()
  runner = unittest.TextTestRunner()
  runner.run(suite)
